package fsoft.com.vn.directory.dao;


import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import fsoft.com.vn.directory.form.Organization;
import fsoft.com.vn.directory.form.Town;

@Repository
public class OrganizationDaoImpl implements OrganizationDao {

	@Autowired
	private SessionFactory sessionFactory;
	private Session session;

	public void addOrganization(Organization organization) {
		sessionFactory.getCurrentSession().save(organization);
	}

	public List<Organization> listOrganization() {
		return sessionFactory.getCurrentSession().createQuery("from Organization").list();
	}
	
	public void addObject(Object object) {
		sessionFactory.getCurrentSession().save(object);
	}
	public List loadOjbects(String className) {
		return sessionFactory.getCurrentSession().createQuery("from " + className).list();
		
	}
	
	public Object findById(String className, int id) {
		return sessionFactory.getCurrentSession().createQuery("from " + className + " where id = " +id).uniqueResult();
		
	}
	
}
